package top.fzqblog.firstapp;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.Inflater;

/**
 * Created by 抽离 on 2017/8/14 0014.
 */

public class SimpleAdapterTestActivity extends Activity {

    private SimpleAdapter simpleAdapter;

    private ListView listView;

    private List<Map<String, Object>> list = new ArrayList<>();

    private Integer[] images = {R.mipmap.bg1, R.mipmap.bg2, R.mipmap.bg3, R.mipmap.bg4, R.mipmap.bg5, R.mipmap.bg6, R.mipmap.bg7, R.mipmap.bg8};

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.simple_adapter_test);
        init();

    }

    private void init() {
        listView = (ListView) findViewById(R.id.simple_adapter_lv);
        for(int i = 0; i < 8; i++){
            Map<String, Object> map = new HashMap<>();
            map.put("title", "标题" + (i + 1));
            map.put("introduce", "介绍" + (i + 1));
            map.put("iv", images[i]);
            list.add(map);
        }
        String from[] = {"iv", "title", "introduce"};
        int to[] = {R.id.iv, R.id.title, R.id.introduce};
        simpleAdapter = new SimpleAdapter(this, list, R.layout.pictextlayout, from, to);
        View view = LayoutInflater.from(this).inflate(R.layout.headerlayout, null);
        listView.addHeaderView(view);
        listView.setAdapter(simpleAdapter);
    }
}
